import logging
import os
from dataclasses import dataclass

import dotenv

# 配置日志
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

class LLMAssistant:

    @classmethod
    def load_config(cls, config_file: str,
                    api_key: str = None,
                    api_base_url: str = None):
        """
        加载环境配置

        Args:
            config_path: .env文件路径
            :param config_file:
            :param api_base_url:
            :param api_key:
        """
        try:
            if config_file is not None and config_file is not "":
                dotenv.load_dotenv(config_file)
            else:
                dotenv.load_dotenv()

            if not api_key or not api_base_url:
                raise ValueError("OPENAI_API_KEY or OPENAI_API_BASE_URL is not set")

            os.environ['OPENAI_API_KEY'] = os.getenv(api_key)
            os.environ['OPENAI_BASE_URL'] = os.getenv(api_base_url)

            logger.info(f"Load config from {config_file} successfully")
        except Exception as e:
            logger.error(f"Error loading config: {e}")
            raise e